{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openai\n",
    "import json\n",
    "from openai import OpenAI\n",
    "import os\n",
    "from tqdm import tqdm\n",
    "import numpy as np\n",
    "\n",
    "# Set your OpenAI API key\n",
    "os.environ['OPENAI_API_KEY'] = YOUR_API_KEY\n",
    "client = OpenAI()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from clair import clair"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Geochat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "qa_list = [json.loads(line) for line in open('Results/outputs_RSBench_new/rsbench_cap_v2.json','r').readlines()]\n",
    "\n",
    "# Iterate over the list and check matches\n",
    "results = []\n",
    "f = open('Results/outputs_RSBench_new/rsbench_cap_v2_gpt.json', 'w') \n",
    "for ii, qa in enumerate(tqdm(qa_list)):\n",
    "    question = qa['question']\n",
    "    ground_truth = qa['ground_truth']\n",
    "    predicted = qa['answer']\n",
    "    clair_score = clair([predicted], [ground_truth], model='gpt-4o')\n",
    "    # print(clair_score)\n",
    "\n",
    "    result = {\n",
    "        'question_id': qa['question_id'],\n",
    "        \"question\": question,\n",
    "        \"ground_truth\": ground_truth,\n",
    "        \"predicted\": predicted,\n",
    "        \"clair\": clair_score[0],\n",
    "        \"clair_reason\": clair_score[1],\n",
    "    }\n",
    "    results.append(result)\n",
    "\n",
    "    f.write(json.dumps(result)+'\\n')\n",
    "    f.flush()\n",
    "\n",
    "f.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
